import React, { Component } from 'react'
import qs from 'querystring'

const data = [
  {id: '001', content: "你好，中国"},
  {id: '002', content: "你好， 中国上海"},
  {id: '003', content: "你好，中国上海松江区车墩镇"},
]

export default class Detail extends Component {
  render() {
    //接收params参数
    // const {id, title} = this.props.match.params

    // querystring 的使用
    // let obj = {name: 'tom', age:18}
    // console.log(qs.stringify(obj))

    // 接收search参数
    // console.log("props", this.props)
    // const {search} = this.props.location
    // console.log("search", search)
    // const {id, title} = qs.parse(search.slice(1))

    // 接收State参数
    const {id, title} = this.props.location.state || {}

    const findResult = data.find((dt) => {
      return dt.id === id
    }) || {}
    return (
      <ul>
        <li>
          <div>ID:{findResult.id}</div>
        </li>
        <li>
          <div>TITLE:{title}</div>
        </li>
        <li>
          <div>CONTENT:{findResult.content}</div>
        </li>
      </ul>
    )
  }
}
